package io.zt.dangyuan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import io.zt.dangyuan.object.AddressBook;
import io.zt.dangyuan.util.Cons;

import com.bumptech.glide.Glide;

import java.util.List;

public class AddressBookAdapter extends BaseAdapter {
	private  LayoutInflater mInflater;
	private List<AddressBook.ListEntity> datas;
	private Context context;

	public AddressBookAdapter(Context context, List<AddressBook.ListEntity> datas) {
		super();
		this.context=context;
		this.datas=datas;
		this.mInflater = LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder=new ViewHolder();
			convertView = mInflater.inflate(R.layout.address_book_item, null);
			holder.tv_itemName = (TextView) convertView.findViewById(R.id.addres_book_name);
			holder.tv_itemphoen = (TextView) convertView.findViewById(R.id.addres_book_phone);
//			holder.iv_image = (ImageView) convertView.findViewById(R.id.addres_book_image);

			convertView.setTag(holder);
		}else {
			holder = (ViewHolder)convertView.getTag();
		}
		AddressBook.ListEntity object =  datas.get(position);
		holder.tv_itemName.setText(object.getRealname());
		holder.tv_itemphoen.setText(object.getMobile());

//		BitmapUtils bitmapUtils = new BitmapUtils(context);
//		bitmapUtils.configMemoryCacheEnabled(true);
//		bitmapUtils.configDefaultLoadingImage(R.drawable.icon_default);
//		bitmapUtils.configDefaultLoadFailedImage(R.drawable.icon_default);
//		bitmapUtils.display(holder.iv_image, Cons.BASE_URL + object.getUserimg());

		Glide.with(context).load(Cons.BASE_URL + object.getUserimg())
				.placeholder(R.drawable.icon_default).into(holder.iv_image);

		return convertView;
	}

	class ViewHolder   {
		TextView  tv_itemName;
		TextView  tv_itemphoen;
		ImageView iv_image;
	}



}